
package gestion_des_note;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class Ajout_cours  extends JDialog {
 // private JTextField [] jtxtNote= new JTextField[3];
  private JPanel jPanel1 = new JPanel();
  private JLabel jLabel1 = new JLabel();
//  private JTextField jtxtNom = new JTextField();
  private JLabel jLabel2 = new JLabel();
  private JLabel jLabel3 = new JLabel();
  private JLabel jLabel4 = new JLabel();
  private JLabel jLabel5 = new JLabel();
  private JLabel jLabel6 = new JLabel();
  private JTextField jtxtlibeleC = new JTextField();
  private JLabel jlblMatrucil = new JLabel();
  private JComboBox jcomboFilier = new JComboBox();
  private JComboBox jcomboGroup = new JComboBox();
  private JButton jbtnEnregistrer = new JButton();
  private JButton jbtnRetour = new JButton();
  private JPanel jPanel3 = new JPanel();
  private FlowLayout flowLayout1 = new FlowLayout();
  private TitledBorder titledBorder1;

  public Ajout_cours() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  private void jbInit() throws Exception {
    titledBorder1 = new TitledBorder("");
    jLabel1.setFont(new java.awt.Font("Dialog", 1, 13));
    jLabel1.setForeground(Color.red);
    jLabel1.setText("ID  :");
    jLabel1.setBounds(new Rectangle(45, 34, 95, 17));
    jPanel1.setLayout(null);
    //jtxtNom.setBackground(Color.lightGray);
   // jtxtNom.setFont(new java.awt.Font("Dialog", 1, 13));
   // jtxtNom.setBorder(BorderFactory.createLineBorder(Color.black));
   // jtxtNom.setBounds(new Rectangle(149, 65, 130, 19));
   // jtxtNom.addFocusListener(new java.awt.event.FocusAdapter() {
    //  public void focusLost(FocusEvent e) {
     //  jtxtNom_focusLost(e);
    //  }
  //  });
    jLabel2.setBackground(SystemColor.inactiveCaptionBorder);
    jLabel2.setFont(new java.awt.Font("Dialog", 1, 13));
    jLabel2.setForeground(Color.red);
  //  jLabel2.setText("  :");
    jLabel2.setBounds(new Rectangle(45, 67, 100, 15));
    jLabel3.setFont(new java.awt.Font("Dialog", 1, 13));
    jLabel3.setForeground(Color.red);
    jLabel3.setText("Libele  :");
    jLabel3.setBounds(new Rectangle(42, 98, 99, 18));
    jLabel4.setFont(new java.awt.Font("Dialog", 1, 13));
    jLabel4.setForeground(Color.red);
    jLabel4.setText("Filiere  :");
    jLabel4.setBounds(new Rectangle(44, 127, 97, 19));
    jLabel5.setFont(new java.awt.Font("Dialog", 1, 13));
    jLabel5.setForeground(Color.red);
    jLabel5.setText("Niveau  :");
    jLabel5.setBounds(new Rectangle(43, 153, 93, 20));
    jLabel6.setFont(new java.awt.Font("Dialog", 1, 13));
    jLabel6.setForeground(Color.red);
  //jLabel6.setText("Notes  :");
  //jLabel6.setBounds(new Rectangle(43, 180, 92, 23));
    jPanel1.setBackground(Color.white);
    jPanel1.setFont(new java.awt.Font("Dialog", 1, 13));
    jtxtlibeleC.setBackground(Color.lightGray);
    jtxtlibeleC.setFont(new java.awt.Font("Dialog", 1, 13));
    jtxtlibeleC.setBorder(BorderFactory.createLineBorder(Color.black));
    jtxtlibeleC.setBounds(new Rectangle(148, 98, 131, 20));
    jtxtlibeleC.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusLost(FocusEvent e) {
        jtxtlibeleC_focusLost(e);
      }
    });
    jtxtlibeleC.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jtxtlibeleC_actionPerformed(e);
      }
    });
    jlblMatrucil.setFont(new java.awt.Font("Dialog", 1, 13));
    jlblMatrucil.setBorder(BorderFactory.createLineBorder(Color.black));
    jlblMatrucil.setOpaque(true);
    jlblMatrucil.setBounds(new Rectangle(148, 34, 131, 20));
    jcomboFilier.setFont(new java.awt.Font("Dialog", 1, 13));
    jcomboFilier.setBorder(BorderFactory.createLineBorder(Color.black));
    jcomboFilier.setBounds(new Rectangle(148, 129, 133, 18));
    jcomboFilier.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jcomboFilier_actionPerformed(e);
      }
    });
    jcomboFilier.addItemListener(new java.awt.event.ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        jcomboFilier_itemStateChanged(e);
      }
    });
    jcomboGroup.setFont(new java.awt.Font("Dialog", 1, 13));
    jcomboGroup.setBorder(BorderFactory.createLineBorder(Color.black));
    jcomboGroup.setBounds(new Rectangle(149, 157, 132, 18));
    jbtnEnregistrer.setBounds(new Rectangle(10, 200, 120, 37));
    jbtnEnregistrer.setFont(new java.awt.Font("Dialog", 1, 13));
    jbtnEnregistrer.setHorizontalTextPosition(SwingConstants.LEFT);
    jbtnEnregistrer.setIcon(new ImageIcon(new java.net.URL("file:///G:/Documents and Settings/Administrateur/Bureau/Projet Gestion des Note Graphique V3A/Projet Gestion des Note2/enregistrer.gif")));
    jbtnEnregistrer.setText("Enregistrer");
    jbtnEnregistrer.setVerticalAlignment(SwingConstants.BOTTOM);
    jbtnEnregistrer.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(MouseEvent e) {
        jbtnEnregistrer_mouseEntered(e);
      }
      public void mouseExited(MouseEvent e) {
        jbtnEnregistrer_mouseExited(e);
      }
    });
    jbtnEnregistrer.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jbtnEnregistrer_actionPerformed(e);
      }
    });
    jbtnRetour.setBounds(new Rectangle(10, 250, 119, 39));
    jbtnRetour.setFont(new java.awt.Font("Dialog", 1, 13));
    jbtnRetour.setHorizontalTextPosition(SwingConstants.LEFT);
    jbtnRetour.setIcon(new ImageIcon(new java.net.URL("file:///G:/Documents and Settings/Administrateur/Bureau/Projet Gestion des Note Graphique V3A/Projet Gestion des Note2/retour.gif")));
    jbtnRetour.setText("Retour");
    jbtnRetour.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(MouseEvent e) {
        jbtnRetour_mouseEntered(e);
      }
      public void mouseExited(MouseEvent e) {
        jbtnRetour_mouseExited(e);
      }
    });
    jbtnRetour.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jbtnRetour_actionPerformed(e);
      }
    });
    jPanel3.setBackground(Color.white);
    jPanel3.setBounds(new Rectangle(148, 186, 134, 105));
    jPanel3.setLayout(flowLayout1);
   /* for(int i=0;i<3;i++){
      jtxtNote[i]=new JTextField();
      jtxtNote[i].setPreferredSize(new Dimension(76, 22));
      jtxtNote[i].setFont(new java.awt.Font("Dialog", 1, 12));
      jtxtNote[i].setBackground(Color.lightGray);
      jtxtNote[i].setBorder(BorderFactory.createLineBorder(Color.black));
      jPanel3.add(jtxtNote[i]);
    }*/
    this.setResizable(false);
    this.setTitle("                             Ajouter Cours   :");
    this.addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowOpened(WindowEvent e) {
        this_windowOpened(e);
      }
    });
    jPanel1.add(jLabel1, null);
    jPanel1.add(jLabel2, null);
    jPanel1.add(jLabel3, null);
    jPanel1.add(jLabel4, null);
    jPanel1.add(jLabel5, null);
   // jPanel1.add(jLabel6, null);
    //jPanel1.add(jtxtNom, null);
    jPanel1.add(jlblMatrucil, null);
    jPanel1.add(jcomboFilier, null);
    jPanel1.add(jcomboGroup, null);
    jPanel1.add(jtxtlibeleC, null);
    jPanel1.add(jPanel3, null);
    jPanel1.add(jbtnEnregistrer, null);
    jPanel1.add(jbtnRetour, null);
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
  }
  public void Retour(){
    dispose() ;
  }
public String Majiscule_premiere_lettre(String mot)
{
  String prmiere_lettre=mot.substring(0,1).toUpperCase();
  String rest_mot=mot.substring(1,mot.length()).toLowerCase();
  String nv_mot="";
  nv_mot=prmiere_lettre+rest_mot;
  return nv_mot;
}
  void jbtnRetour_actionPerformed(ActionEvent e) {
Retour();
  }

  void jbtnEnregistrer_actionPerformed(ActionEvent e) {
  Classe cls = new Classe();
  Cours cour = new Cours();
  String mtr;
  double [] nte= new double[3];
 // Cours etd =new Cours();
  boolean  vide=false;
  boolean isNumeric=true;
  int idcr=0;
  String nom="";
  String libelec="";
  String filier="";
  int group=0;

  // tester si les champ de saisi sont vides
/*  for(int i=0;i<3;i++)
  {
    if(jtxtNote[i].getText().equals(""))
    {
      vide=true;
    }
  }*/
 /* if((jtxtNom.getText().equals("")) || (jtxtlibeleC.getText().equals("")) || (jcomboFilier.getSelectedIndex()==-1)|| (jcomboGroup.getSelectedIndex()==-1) || vide==true)
  {
    JOptionPane.showMessageDialog(null,"Saisi incomplete?","Gestion carnet de notes",JOptionPane.WARNING_MESSAGE);
  }
   else //si non on va enregistrer dans la vecteur
   {*/
   /*  for(int i=0;i<3;i++)
  {
    try
    {
    double nt= Double.valueOf(jtxtNote[i].getText()).doubleValue();
     nte[i]=nt;
    }
    catch(NumberFormatException ex)
    {
      isNumeric=false;
      JOptionPane.showMessageDialog(null,"Saisi erroné veuillez saisir des chiffre?","Gestion carnet de notes",JOptionPane.WARNING_MESSAGE);
       jtxtNote[i].setText("");
       jtxtNote[i].requestFocus();
       i=3;
    }
  }*/
  idcr=Integer.valueOf(jlblMatrucil.getText()).intValue();
 // nom=jtxtNom.getText();
  libelec=jtxtlibeleC.getText();
  filier= String.valueOf(jcomboFilier.getItemAt(jcomboFilier.getSelectedIndex()));
  group= Integer.valueOf(String.valueOf(jcomboGroup.getItemAt(jcomboGroup.getSelectedIndex()))).intValue();
  if(isNumeric)
  {
  cour.AjoutCours(idcr,libelec,filier,group);
  JOptionPane.showMessageDialog(null,"      Enregistrement effectué","Gestion carnet de notes",JOptionPane.INFORMATION_MESSAGE);
  // pour increment� le matricule automatiqument
  mtr= String.valueOf(((Cours) cour.glossaireCours.elementAt(cour.glossaireCours.size()-1)).getIDc()+1) ;
  jlblMatrucil.setText(mtr);
  // pour vider les champs de saisi
  //jtxtNom.setText("");
  jtxtlibeleC.setText("");
 /* for(int i=0;i<3;i++)
  {
    jtxtNote[i].setText("");
  }*/

  // jtxtNom.requestFocus() ;
   }
   }
 // }

  void this_windowOpened(WindowEvent e) {
   // saisir le matricule automatiqument
    Classe cls = new Classe();
    Cours cour = new Cours();
    String mtr;
    if(cour.glossaireCours.isEmpty())
      mtr=String.valueOf(1);
    else
    {
    mtr= String.valueOf(((Cours) cour.glossaireCours.elementAt(cour.glossaireCours.size()-1)).getIDc()+1) ;
    }
    jlblMatrucil.setText(mtr);
    //remplir le jcomboFilier avec la liste des filier qui existe
    DefaultComboBoxModel mdl_filier= new  DefaultComboBoxModel();
    jcomboFilier.setModel(mdl_filier);

    for(int i=0;i<cls.glossaireFilier.size();i++)
    {
   String filier= ((Classe)cls.glossaireFilier.elementAt(i)).getFilier();
   mdl_filier.addElement(filier);
    }


  }

  void jcomboFilier_itemStateChanged(ItemEvent e) {
  Classe cls = new Classe();
  DefaultComboBoxModel mdl_Group= new  DefaultComboBoxModel();
  jcomboGroup.setModel(mdl_Group);
  Object obj=e.getItem() ;
  String selectioné= (String) obj;
  String nb;
  int nbr=0;
  int i;
  // remplir jcomboGroup avec les group qui existe dans la filier selection�
  for(i=0;i<cls.glossaireFilier.size();i++)
    {
    String filier= ((Classe)cls.glossaireFilier.elementAt(i)).getFilier();
    if(filier.equals(selectioné))
    {
      nbr= ((Classe ) cls.glossaireFilier.elementAt(i)).getGroup();
      break;
    }
    }
    for(i=0;i<nbr;i++){
      nb=String.valueOf(i+1);
      mdl_Group.addElement(nb);
    }

  }

  void jbtnEnregistrer_mouseEntered(MouseEvent e) {
setCursor(new Cursor(12));
  }

  void jbtnEnregistrer_mouseExited(MouseEvent e) {
setCursor(new Cursor(0));
  }

  void jbtnRetour_mouseEntered(MouseEvent e) {
setCursor(new Cursor(12));
  }

  void jbtnRetour_mouseExited(MouseEvent e) {
setCursor(new Cursor(0));
  }

 /* void jtxtNom_focusLost(FocusEvent e) {
jtxtNom.setText(jtxtNom.getText().toUpperCase());
  }*/

  void jtxtlibeleC_actionPerformed(ActionEvent e) {
  }

  void jtxtlibeleC_focusLost(FocusEvent e) {
  if(jtxtlibeleC.getText().length()!=0)
jtxtlibeleC.setText(Majiscule_premiere_lettre(jtxtlibeleC.getText()));
  }

  void jcomboFilier_actionPerformed(ActionEvent e) {

  }
}

